var SendPhoneCode = require('../libs/template/SendPhoneCode.js');
var c = require('../libs/common.js');
var config = require('../libs/config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    password: true,
    yanjing: '/images/biyan.png',
    status: 1,
    flag: 0,
    color: '#E0E0E0',
    hidden: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  loginclick: function() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  forgetPhone: function(e) {
    var forgetPhone = e.detail.value;
    this.setData({
      forgetPhone: forgetPhone
    });
  },
  //获取手机号--忘记密码
  sendcodeforget: function() {
    var phonenum = this.data.forgetPhone;
    SendPhoneCode.sendcode(phonenum, this, 'forgetpass');
  },
  //获取验证码
  forgetPhoneCode: function(e) {
    var forgetPhoneCode = e.detail.value;
    this.setData({
      forgetPhoneCode: forgetPhoneCode
    });
  },
  //密码
  forgetPassword: function(e) {
    var forgetPassword = e.detail.value;
    this.setData({
      forgetPassword: forgetPassword
    });
  },
  //确定修改密码
  gorgetclick: function() {
    var forgetPassword = this.data.forgetPassword;
    var forgetPhoneCode = this.data.forgetPhoneCode;
    var forgetPhone = this.data.forgetPhone;
    c.ajax(
      config.hostapi + '/PassWord/forgetPassSubmit', {
        phone: forgetPhone,
        phonecode: forgetPhoneCode,
        password: forgetPassword,
        utype: 'user',
      },
      res => {
        if (res.data.code == 100) {
          wx.setStorageSync('userinfo', res.data.data);
          wx.showToast({
            title: res.data.info,
            image:'/images/dui.png'
          })
          setTimeout(function () {
            wx.navigateTo({
              url: '/pages/login/login',
            })
          }, 1000)
        } else {
          wx.showToast({
            title: res.data.info,
            image: '/images/closered.png'
          })
        };
      }
    )
  },
  close: function () {
    this.setData({
      phone: ''
    })
  },
  biyan: function (e) {
    var status = e.currentTarget.dataset.status == 1 ? 2 : 1;
    if (status == 2) {
      var yanjing = '/images/zhengyan.png';
      var password = false;
    } else {
      var yanjing = '/images/biyan.png';
      var password = true;
    }
    this.setData({
      password: password,
      yanjing: yanjing,
      status: status
    })
  }


})